package com.rabbitmq.demo.dmp;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

@Profile(value="dmp")
@Configuration
public class RabbitMQConfig {

    @Bean
    public Queue queue(){
        return new Queue("delayed.queue");
    }

    @Bean
    public CustomExchange delayedMessageExchange(){
        CustomExchange customExchange = new CustomExchange("delayed.message.exchange","x-delayed-message");
        customExchange.addArgument("x-delayed-type","direct");
        return customExchange;
    }

    @Bean
    public Binding binding(){
        return BindingBuilder.bind(queue()).to(delayedMessageExchange()).with(queue().getName()).noargs();
    }

    @Profile(value = "sender")
    @Bean
    public Sender sender(){
        return new Sender();
    }

    @Profile(value = "receiver")
    @Bean
    public Receiver receiver(){
        return new Receiver();
    }
}
